﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using gregn6Lib;
using System.Configuration;
using Common;
using System.IO;
using NursingFormSystem.Model;
using DevExpress.XtraEditors;
using SQLDLL;
using NursingFormSystem.NurFormsService;

namespace NursingFormSystem.HandoverSlip
{
    public partial class HandoverPrint : Form
    {
        private GridppReport Report = new GridppReport();
        NurFormsService.NursingForm formService = new NurFormsService.NursingForm();
        private string p1;
        private int p2;
        private int p3;

        public HandoverPrint()
        {
            InitializeComponent();
        }

        public HandoverPrint(string p1, int p2, int p3)
        {
            // TODO: Complete member initialization

            InitializeComponent();
            var ret = formService.GetNursingFormRecord(p1, p2, p3);
            if (ret.Code == 1)
            {
                List<NursingFormRecord> list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<NursingFormRecord>>(ret.D);
                NursingFormRecord record1 = list[0];
                PatientHandover ps = XmlUtil.XMLToObject<PatientHandover>(record1.NursingFormData, Encoding.UTF8);
                //NursingFormRecord record1 = ret.D;
                //PatientHandover ps = XmlUtil.XMLToObject<PatientHandover>(record1.NursingFormData, Encoding.UTF8);
                //意识
                string YiShi = "";
                string YiShi1 = "";
                string YiShi2 = "";
                if (ps.RuShouShuShi.YiShi == "")
                    YiShi = "1000";
                else
                    YiShi = ps.RuShouShuShi.YiShi;
                if (ps.ChuShouShuShi.YiShi == "")
                    YiShi1 = "1000";
                else
                    YiShi1 = ps.ChuShouShuShi.YiShi;
                if (ps.ChuPACU.YiShi == "")
                    YiShi2 = "1000";
                else
                    YiShi2 = ps.ChuPACU.YiShi;
                //血压
                string[] XueYa = { "", "" };
                if (!string.IsNullOrEmpty(ps.RuShouShuShi.XueYa))
                    XueYa = ps.RuShouShuShi.XueYa.Split('/');

                string[] XueYa1 = { "", "" };
                if (!string.IsNullOrEmpty(ps.ChuPACU.XueYa))
                    XueYa1 = ps.ChuPACU.XueYa.Split('/');

                //腕带
                string WanDai = "";
                string WanDai1 = "";
                string WanDai2 = "";
                if (ps.RuShouShuShi.WanDai == "")
                    WanDai = "1000";
                else
                    WanDai = ps.RuShouShuShi.WanDai;
                if (ps.ChuShouShuShi.WanDai == "")
                    WanDai1 = "1000";
                else
                    WanDai1 = ps.ChuShouShuShi.WanDai;
                if (ps.ChuPACU.WanDai == "")
                    WanDai2 = "1000";
                else
                    WanDai2 = ps.ChuPACU.WanDai;
                //手术部位标识
                string ShouShuBuWeiBiaoShi = "";
                if (ps.RuShouShuShi.ShouShuBuWeiBiaoShi == "")
                    ShouShuBuWeiBiaoShi = "1000";
                else
                    ShouShuBuWeiBiaoShi = ps.RuShouShuShi.ShouShuBuWeiBiaoShi;
                //备皮
                string BeiPi = "";
                if (ps.RuShouShuShi.BeiPi == "")
                    BeiPi = "1000";
                else
                    BeiPi = ps.RuShouShuShi.BeiPi;
                //更衣
                string GenYi = "";
                if (ps.RuShouShuShi.GenYi == "")
                    GenYi = "1000";
                else
                    GenYi = ps.RuShouShuShi.GenYi;
                //心脏起搏器
                string XinZangQiBoQi = "";
                if (ps.RuShouShuShi.XinZangQiBoQi == "")
                    XinZangQiBoQi = "1000";
                else
                    XinZangQiBoQi = ps.RuShouShuShi.XinZangQiBoQi;
                //植入物
                string ZhiRuWu = "";
                if (ps.RuShouShuShi.ZhiRuWu == "")
                    ZhiRuWu = "1000";
                else
                    ZhiRuWu = ps.RuShouShuShi.ZhiRuWu;
                //义齿
                string YiChi = "";
                if (ps.RuShouShuShi.YiChi == "")
                    YiChi = "1000";
                else
                    YiChi = ps.RuShouShuShi.YiChi;
                //随身饰物
                string SuiShenShiWu = "";
                string SuiShenShiWu1 = "";
                string SuiShenShiWu2 = "";
                if (ps.RuShouShuShi.SuiShenShiWu == "")
                    SuiShenShiWu = "1000";
                else
                    SuiShenShiWu = ps.RuShouShuShi.SuiShenShiWu;
                if (ps.ChuShouShuShi.SuiShenShiWu == "")
                    SuiShenShiWu1 = "1000";
                else
                    SuiShenShiWu1 = ps.ChuShouShuShi.SuiShenShiWu;
                if (ps.ChuPACU.SuiShenShiWu == "")
                    SuiShenShiWu2 = "1000";
                else
                    SuiShenShiWu2 = ps.ChuPACU.SuiShenShiWu;
                //药物过敏史
                string YaoWuGuoMinShi = "";
                if (ps.RuShouShuShi.YaoWuGuoMinShi == "")
                    YaoWuGuoMinShi = "1000";
                else
                    YaoWuGuoMinShi = ps.RuShouShuShi.YaoWuGuoMinShi;
                //血制品
                string XueZhiPin = "";
                string XueZhiPin1 = "";
                if (ps.ChuShouShuShi.XueZhiPin == "")
                    XueZhiPin = "1000";
                else
                    XueZhiPin = ps.ChuShouShuShi.XueZhiPin;
                if (ps.ChuPACU.XueZhiPin == "")
                    XueZhiPin1 = "1000";
                else
                    XueZhiPin1 = ps.ChuPACU.XueZhiPin;
                //PCA泵
                string PCA_Beng = "";
                string PCA_BengTuJing = "";
                if (ps.ChuPACU.PCA_Beng == "")
                    PCA_Beng = "1000";
                else
                    PCA_Beng = ps.ChuPACU.PCA_Beng;
                if (ps.ChuPACU.PCA_BengTuJing == "")
                    PCA_BengTuJing = "1000";
                else
                    PCA_BengTuJing = ps.ChuPACU.PCA_BengTuJing;
                //患者去向
                string HuanZheQuXiang = "";
                string HuanZheQuXiang1 = "";
                string HuanZheQuXiang2 = "";
                if (ps.RuShouShuShi.HuanZheQuXiang == "")
                    HuanZheQuXiang = "1000";
                else
                    HuanZheQuXiang = ps.RuShouShuShi.HuanZheQuXiang;
                if (ps.ChuShouShuShi.HuanZheQuXiang == "")
                    HuanZheQuXiang1 = "1000";
                else
                    HuanZheQuXiang1 = ps.ChuShouShuShi.HuanZheQuXiang;
                if (ps.ChuPACU.HuanZheQuXiang == "")
                    HuanZheQuXiang2 = "1000";
                else
                    HuanZheQuXiang2 = ps.ChuPACU.HuanZheQuXiang;

                string select = @"select '" + ps.RiQi + @"' AS RiQi ,'" + ps.ShuQianZhenDuan + @"' AS SQZD,'" + ps.NiShouShuMingCheng + @"' AS NSSMC,(CASE '" + YiShi + @"' WHEN 0 THEN 1 ELSE 0 END) AS Ru_YiShi1,(CASE '" + YiShi + @"' WHEN 1 THEN 1 ELSE 0 END) AS Ru_YiShi2,(CASE '" + YiShi + @"' WHEN 2 THEN 1 ELSE 0 END) AS Ru_YiShi3,
(CASE SUBSTRING('" + ps.RuShouShuShi.TeShuGanRan + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_TSGR1,(CASE SUBSTRING('" + ps.RuShouShuShi.TeShuGanRan + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_TSGR2,(CASE SUBSTRING('" + ps.RuShouShuShi.TeShuGanRan + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_TSGR3,(CASE SUBSTRING('" + ps.RuShouShuShi.TeShuGanRan + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_TSGR4,(CASE SUBSTRING('" + ps.RuShouShuShi.TeShuGanRan + @"',9,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_TSGR5,
'" + ps.RuShouShuShi.TiWen + @"' AS Ru_TiWen,'" + ps.RuShouShuShi.MaiBo + @"' AS Ru_MaiBo,'" + ps.RuShouShuShi.HuXi + @"' AS Ru_HuXi,'" + XueYa[0] + @"' AS Ru_XueYa1,'" + XueYa[1] + @"' AS Ru_XueYa2,
(CASE '" + WanDai + @"' WHEN 0 THEN 1 ELSE 0 END) AS Ru_WanDai1,(CASE '" + WanDai + @"' WHEN 1 THEN 1 ELSE 0 END) AS Ru_WanDai2,(CASE '" + ShouShuBuWeiBiaoShi + @"' WHEN 0 THEN 1 ELSE 0 END) AS Ru_SSBWBS1,(CASE '" + ShouShuBuWeiBiaoShi + @"' WHEN 1 THEN 1 ELSE 0 END) AS Ru_SSBWBS2,(CASE '" + BeiPi + @"' WHEN 0 THEN 1 ELSE 0 END) AS Ru_BeiPi1,(CASE '" + BeiPi + @"' WHEN 1 THEN 1 ELSE 0 END) AS Ru_BeiPi2,
(CASE '" + GenYi + @"' WHEN 0 THEN 1 ELSE 0 END) AS Ru_GengYi1,(CASE '" + GenYi + @"' WHEN 1 THEN 1 ELSE 0 END) AS Ru_GengYi2,(CASE '" + XinZangQiBoQi + @"' WHEN 0 THEN 1 ELSE 0 END) AS Ru_XZQBQ1,(CASE '" + XinZangQiBoQi + @"' WHEN 1 THEN 1 ELSE 0 END) AS Ru_XZQBQ2,(CASE '" + ZhiRuWu + @"' WHEN 0 THEN 1 ELSE 0 END) AS Ru_ZhiRuWu1,(CASE '" + ZhiRuWu + @"' WHEN 1 THEN 1 ELSE 0 END) AS Ru_ZhiRuWu2,
(CASE '" + YiChi + @"' WHEN 0 THEN 1 ELSE 0 END) AS Ru_YiChi1,(CASE '" + YiChi + @"' WHEN 1 THEN 1 ELSE 0 END) AS Ru_YiChi2,(CASE '" + YiChi + @"' WHEN 2 THEN 1 ELSE 0 END) AS Ru_YiChi3,(CASE '" + SuiShenShiWu + @"' WHEN 0 THEN 1 ELSE 0 END) AS Ru_SSSW1,(CASE '" + SuiShenShiWu + @"' WHEN 1 THEN 1 ELSE 0 END) AS Ru_SSSW2,'" + ps.RuShouShuShi.SSSW_MingCheng + @"' AS Ru_SSSWMC,'" + ps.RuShouShuShi.SSSW_JianShu + @"' AS Ru_SSSWJS,
(CASE SUBSTRING('" + ps.RuShouShuShi.XieDaiWuPin + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_XDWP1,(CASE SUBSTRING('" + ps.RuShouShuShi.XieDaiWuPin + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_XDWP2,(CASE SUBSTRING('" + ps.RuShouShuShi.XieDaiWuPin + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_XDWP3,(CASE SUBSTRING('" + ps.RuShouShuShi.XieDaiWuPin + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_XDWP4,(CASE SUBSTRING('" + ps.RuShouShuShi.XieDaiWuPin + @"',9,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_XDWP5,'" + ps.RuShouShuShi.XDWP_QiTa + @"' AS Ru_XDWPMC,
(CASE '" + YaoWuGuoMinShi + @"' WHEN 0 THEN 1 ELSE 0 END) AS Ru_YWGMS1,(CASE '" + YaoWuGuoMinShi + @"' WHEN 1 THEN 1 ELSE 0 END) AS Ru_YWGMS2,'" + ps.RuShouShuShi.YWGMS_QiTa + @"' AS Ru_YWGMSMC,
(CASE SUBSTRING('" + ps.RuShouShuShi.JingMaiTongLu + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_JMTL1,(CASE SUBSTRING('" + ps.RuShouShuShi.JingMaiTongLu + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_JMTL2,(CASE SUBSTRING('" + ps.RuShouShuShi.JingMaiTongLu + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_JMTL3,(CASE SUBSTRING('" + ps.RuShouShuShi.JingMaiTongLu + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_JMTL4,(CASE SUBSTRING('" + ps.RuShouShuShi.JingMaiTongLu + @"',9,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_JMTL5,
(CASE SUBSTRING('" + ps.RuShouShuShi.ShuQianLiuZhi + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_SQLZ1,(CASE SUBSTRING('" + ps.RuShouShuShi.ShuQianLiuZhi + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_SQLZ2,(CASE SUBSTRING('" + ps.RuShouShuShi.ShuQianLiuZhi + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_SQLZ3,(CASE SUBSTRING('" + ps.RuShouShuShi.ShuQianLiuZhi + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_SQLZ4,'" + ps.RuShouShuShi.SQLZ_MingCheng + @"' AS Ru_SQLZMC,
(CASE SUBSTRING('" + ps.RuShouShuShi.PiFuQingKuang + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_PFQK1,(CASE SUBSTRING('" + ps.RuShouShuShi.PiFuQingKuang + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_PFQK2,(CASE SUBSTRING('" + ps.RuShouShuShi.PiFuQingKuang + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS Ru_PFQK3,'" + ps.RuShouShuShi.PFQK_NeiRong + @"' AS Ru_PFQKMC,
(CASE '" + HuanZheQuXiang + @"' WHEN 0 THEN 1 ELSE 0 END) AS Ru_HZQX1,(CASE '" + HuanZheQuXiang + @"' WHEN 1 THEN 1 ELSE 0 END) AS Ru_HZQX2,(CASE '" + HuanZheQuXiang + @"' WHEN 2 THEN 1 ELSE 0 END) AS Ru_HZQX3,'" + ps.RuShouShuShi.HuShiQianMing + @"' AS Ru_HSQM,'" + ps.RuShouShuShi.ShouShuShiHuShiQianMing + @"' AS Ru_SSSHSQM,

(CASE '" + YiShi1 + @"' WHEN 0 THEN 1 ELSE 0 END) AS Chu_YiShi1,(CASE '" + YiShi1 + @"' WHEN 1 THEN 1 ELSE 0 END) AS Chu_YiShi2,(CASE '" + YiShi1 + @"' WHEN 2 THEN 1 ELSE 0 END) AS Chu_YiShi3,(CASE '" + WanDai1 + @"' WHEN 0 THEN 1 ELSE 0 END) AS Chu_WanDai1,(CASE '" + WanDai1 + @"' WHEN 1 THEN 1 ELSE 0 END) AS Chu_WanDai2,
(CASE SUBSTRING('" + ps.ChuShouShuShi.XieDaiWuPin + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_XDWP1,(CASE SUBSTRING('" + ps.ChuShouShuShi.XieDaiWuPin + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_XDWP2,(CASE SUBSTRING('" + ps.ChuShouShuShi.XieDaiWuPin + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_XDWP3,(CASE SUBSTRING('" + ps.ChuShouShuShi.XieDaiWuPin + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_XDWP4,'" + ps.ChuShouShuShi.XDWP_QiTa + @"' AS Chu_XDWPMC,
(CASE '" + SuiShenShiWu1 + @"' WHEN 0 THEN 1 ELSE 0 END) AS Chu_SSSW1,(CASE '" + SuiShenShiWu1 + @"' WHEN 1 THEN 1 ELSE 0 END) AS Chu_SSSW2,'" + ps.ChuShouShuShi.SSSW_MingCheng + @"' AS Chu_SSSWMC,'" + ps.ChuShouShuShi.SSSW_JianShu + @"' AS Chu_SSSWJS,(CASE '" + XueZhiPin + @"' WHEN 0 THEN 1 ELSE 0 END) AS Chu_XueZiPin1,(CASE '" + XueZhiPin + @"' WHEN 1 THEN 1 ELSE 0 END) AS Chu_XueZiPin2,'" + ps.ChuShouShuShi.XZP_MingChengDaiShu + @"' AS Chu_XueZiPinMC,
(CASE SUBSTRING('" + ps.ChuShouShuShi.JingMaiTongLu + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_JMTL1,(CASE SUBSTRING('" + ps.ChuShouShuShi.JingMaiTongLu + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_JMTL2,(CASE SUBSTRING('" + ps.ChuShouShuShi.JingMaiTongLu + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_JMTL3,(CASE SUBSTRING('" + ps.ChuShouShuShi.JingMaiTongLu + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_JMTL4,(CASE SUBSTRING('" + ps.ChuShouShuShi.JingMaiTongLu + @"',9,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_JMTL5,
(CASE SUBSTRING('" + ps.ChuShouShuShi.ShuHouLiuZhi + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_SHLZ1,(CASE SUBSTRING('" + ps.ChuShouShuShi.ShuHouLiuZhi + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_SHLZ2,(CASE SUBSTRING('" + ps.ChuShouShuShi.ShuHouLiuZhi + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_SHLZ3,(CASE SUBSTRING('" + ps.ChuShouShuShi.ShuHouLiuZhi + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_SHLZ4,(CASE SUBSTRING('" + ps.ChuShouShuShi.ShuHouLiuZhi + @"',9,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_SHLZ5,'" + ps.ChuShouShuShi.SHLZ_QiTa + @"' AS Chu_SHLZMC,
(CASE SUBSTRING('" + ps.ChuShouShuShi.PiFuQingKuang + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_PFQK1,(CASE SUBSTRING('" + ps.ChuShouShuShi.PiFuQingKuang + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_PFQK2,(CASE SUBSTRING('" + ps.ChuShouShuShi.PiFuQingKuang + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS Chu_PFQK3,'" + ps.ChuShouShuShi.PFQK_NeiRong + @"' AS Chu_PFQKMC,
(CASE '" + HuanZheQuXiang1 + @"' WHEN 0 THEN 1 ELSE 0 END) AS Chu_HZQX1,(CASE '" + HuanZheQuXiang1 + @"' WHEN 1 THEN 1 ELSE 0 END) AS Chu_HZQX2,(CASE '" + HuanZheQuXiang1 + @"' WHEN 2 THEN 1 ELSE 0 END) AS Chu_HZQX3,'" + ps.ChuShouShuShi.ShouShuShiHuShiQianMing + @"' AS Chu_SSSHSQM,'" + ps.ChuShouShuShi.HuShiQianMing + @"' AS Chu_HSQM,

(CASE '" + YiShi2 + @"' WHEN 0 THEN 1 ELSE 0 END) AS PACU_YiShi1,(CASE '" + YiShi2 + @"' WHEN 1 THEN 1 ELSE 0 END) AS PACU_YiShi2,(CASE '" + YiShi2 + @"' WHEN 2 THEN 1 ELSE 0 END) AS PACU_YiShi3,'" + ps.ChuPACU.MaiBo + @"' AS  PACU_MaiBo,'" + XueYa1[0] + @"' AS PACU_XueYa1,'" + XueYa1[1] + @"' AS PACU_XueYa2,'" + ps.ChuPACU.XueYangBaoHeDu + @"' AS PACU_XYBHD,
(CASE '" + WanDai2 + @"' WHEN 0 THEN 1 ELSE 0 END) AS PACU_WanDai1,(CASE '" + WanDai2 + @"' WHEN 1 THEN 1 ELSE 0 END) AS PACU_WanDai2,
(CASE SUBSTRING('" + ps.ChuPACU.XieDaiWuPin + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_XDWP1,(CASE SUBSTRING('" + ps.ChuPACU.XieDaiWuPin + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_XDWP2,(CASE SUBSTRING('" + ps.ChuPACU.XieDaiWuPin + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_XDWP3,(CASE SUBSTRING('" + ps.ChuPACU.XieDaiWuPin + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_XDWP4,'" + ps.ChuPACU.XDWP_QiTa + @"' AS PACU_XDWPMC,
(CASE '" + SuiShenShiWu2 + @"' WHEN 0 THEN 1 ELSE 0 END) AS PACU_SSSW1,(CASE '" + SuiShenShiWu2 + @"' WHEN 1 THEN 1 ELSE 0 END) AS PACU_SSSW2,'" + ps.ChuPACU.SSSW_MingCheng + @"' AS PACU_SSSWMC,'" + ps.ChuPACU.SSSW_JianShu + @"' AS PACU_SSSWJS,
(CASE '" + XueZhiPin1 + @"' WHEN 0 THEN 1 ELSE 0 END) AS PACU_XueZiPin1,(CASE '" + XueZhiPin1 + @"' WHEN 1 THEN 1 ELSE 0 END) AS PACU_XueZiPin2,'" + ps.ChuPACU.XZP_MingChengDaiShu + @"' AS PACU_XueZiPinMC,
(CASE SUBSTRING('" + ps.ChuPACU.JingMaiTongLu + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_JMTL1,(CASE SUBSTRING('" + ps.ChuPACU.JingMaiTongLu + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_JMTL2,(CASE SUBSTRING('" + ps.ChuPACU.JingMaiTongLu + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_JMTL3,(CASE SUBSTRING('" + ps.ChuPACU.JingMaiTongLu + @"',7,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_JMTL4,(CASE SUBSTRING('" + ps.ChuPACU.JingMaiTongLu + @"',9,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_JMTL5,
(CASE '" + PCA_Beng + @"' WHEN 0 THEN 1 ELSE 0 END) AS PACU_PCABeng1,(CASE '" + PCA_Beng + @"' WHEN 1 THEN 1 ELSE 0 END) AS PACU_PCABeng2,(CASE '" + PCA_BengTuJing + @"' WHEN 0 THEN 1 ELSE 0 END) AS PACU_PCABengTJ1,(CASE '" + PCA_BengTuJing + @"' WHEN 1THEN 1 ELSE 0 END) AS PACU_PCABengTJ2,
(CASE SUBSTRING('" + ps.ChuPACU.ShuHouLiuZhi + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_SHLZ1,(CASE SUBSTRING('" + ps.ChuPACU.ShuHouLiuZhi + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_SHLZ2,(CASE SUBSTRING('" + ps.ChuPACU.ShuHouLiuZhi + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_SHLZ3,'" + ps.ChuPACU.SHLZ_NeiRong + @"' AS PACU_SHLZMC,
(CASE SUBSTRING('" + ps.ChuPACU.PiFuQingKuang + @"',1,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_PFQK1,(CASE SUBSTRING('" + ps.ChuPACU.PiFuQingKuang + @"',3,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_PFQK2,(CASE SUBSTRING('" + ps.ChuPACU.PiFuQingKuang + @"',5,1) WHEN 0 THEN 0 ELSE 1 END) AS PACU_PFQK3,'" + ps.ChuPACU.PFQK_NeiRong + @"' AS PACU_PFQKMC,
(CASE '" + HuanZheQuXiang2 + @"' WHEN 0 THEN 1 ELSE 0 END) AS PACU_HZQX1,(CASE '" + HuanZheQuXiang2 + @"' WHEN 1 THEN 1 ELSE 0 END) AS PACU_HZQX2,'" + ps.ChuPACU.PACU_YiShiQianMing + @"' AS PACU_PACUYSQM,'" + ps.ChuPACU.HuShiQianMing + @"' AS PACU_HSQM,
b.PATIENT_NAME,b.SEX,b.AGE,b.NURSE_CELL_NAME,b.DEPARTMENT_NAME,b.BED_NO,b.PATIENT_ID  
              from NursingFormRecord as a left join V_YDHL_PATIENT b on a.PatientId=b.PATIENT_ID and a.VisitId=b.VISIT_ID where a.PatientId  = '" + p1 + "' and a.VisitId='" + p2 + "' and a.FormId='" + p3 + "' ";

                //设置 ShowPrintDlg 属性，让点击工具栏中的打印按钮时不显示打印对话框
                axGRPrintViewer1.ShowPrintDlg = false;

                try
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + @"\GRFModel\Ydhl_GRF\手术患者交接单.grf"))
                    {
                        Report.LoadFromFile(System.Windows.Forms.Application.StartupPath + @"\GRFModel\Ydhl_GRF\手术患者交接单.grf");
                    }
                    else
                    {
                        Report.LoadFromFile(@"../../Ydhl_GRF/手术患者交接单.grf");
                    }
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show("加载临时医嘱表单失败，请检查文件Ydhl_GRF/手术患者交接单.grf是否存在");
                    WriteLog.WriteLogString(ex.Message + ".  加载临时医嘱表单失败，请检查文件Ydhl_GRF/Order-LZ.grf是否存在");
                }

                Report.DetailGrid.Recordset.QuerySQL = select;

                axGRPrintViewer1.Report = Report;
                axGRPrintViewer1.Start();
            }
            else if (ret.Code == 2)
            {
                string select = @"select '' AS RiQi ,'' AS SQZD,'' AS NSSMC,0 AS Ru_YiShi1,0 AS Ru_YiShi2,0 AS Ru_YiShi3,
0 AS Ru_TSGR1,0 AS Ru_TSGR2,0 AS Ru_TSGR3,0 AS Ru_TSGR4,0 AS Ru_TSGR5,'' AS Ru_TiWen,'' AS Ru_MaiBo,'' AS Ru_HuXi,'' AS Ru_XueYa1,'' AS Ru_XueYa2,
0 AS Ru_WanDai1,0 AS Ru_WanDai2,0 AS Ru_SSBWBS1,0 AS Ru_SSBWBS2,0 AS Ru_BeiPi1,0 AS Ru_BeiPi2,0 AS Ru_GengYi1,0 AS Ru_GengYi2,0 AS Ru_XZQBQ1,0 AS Ru_XZQBQ2,0 AS Ru_ZhiRuWu1,0 AS Ru_ZhiRuWu2,
0 AS Ru_YiChi1,0 AS Ru_YiChi2,0 AS Ru_YiChi3,0 AS Ru_SSSW1,0 AS Ru_SSSW2,'' AS Ru_SSSWMC,'' AS Ru_SSSWJS,0 AS Ru_XDWP1,0 AS Ru_XDWP2,0 AS Ru_XDWP3,0 AS Ru_XDWP4,0 AS Ru_XDWP5,'' AS Ru_XDWPMC,0 AS Ru_YWGMS1,0 AS Ru_YWGMS2,'' AS Ru_YWGMSMC,
0 AS Ru_JMTL1,0 AS Ru_JMTL2,0 AS Ru_JMTL3,0 AS Ru_JMTL4,0 AS Ru_JMTL5,0 AS Ru_SQLZ1,0 AS Ru_SQLZ2,0 AS Ru_SQLZ3,0 AS Ru_SQLZ4,'' AS Ru_SQLZMC,
0 AS Ru_PFQK1,0 AS Ru_PFQK2,0 AS Ru_PFQK3,'' AS Ru_PFQKMC,0 AS Ru_HZQX1,0 AS Ru_HZQX2,0 AS Ru_HZQX3,'' AS Ru_HSQM,'' AS Ru_SSSHSQM,

0 AS Chu_YiShi1,0 AS Chu_YiShi2,0 AS Chu_YiShi3,0 AS Chu_WanDai1,0 AS Chu_WanDai2,0 AS Chu_XDWP1,0 AS Chu_XDWP2,0 AS Chu_XDWP3,0 AS Chu_XDWP4,'' AS Chu_XDWPMC,
0 AS Chu_SSSW1,0 AS Chu_SSSW2,'' AS Chu_SSSWMC,'' AS Chu_SSSWJS,0 AS Chu_XueZiPin1,0 AS Chu_XueZiPin2,'' AS Chu_XueZiPinMC,0 AS Chu_JMTL1,0 AS Chu_JMTL2,0 AS Chu_JMTL3,0 AS Chu_JMTL4,0 AS Chu_JMTL5,
0 AS Chu_SHLZ1,0 AS Chu_SHLZ2,0 AS Chu_SHLZ3,0 AS Chu_SHLZ4,0 AS Chu_SHLZ5,'' AS Chu_SHLZMC,0 AS Chu_PFQK1,0 AS Chu_PFQK2,0 AS Chu_PFQK3,'' AS Chu_PFQKMC,0 AS Chu_HZQX1,0 AS Chu_HZQX2,0 AS Chu_HZQX3,'' AS Chu_SSSHSQM,'' AS Chu_HSQM,

0 AS PACU_YiShi1,0 AS PACU_YiShi2,0 AS PACU_YiShi3,'' AS  PACU_MaiBo,'' AS PACU_XueYa1,'' AS PACU_XueYa2,'0' AS PACU_XYBHD,0 AS PACU_WanDai1,0 AS PACU_WanDai2,
0 AS PACU_XDWP1,0 AS PACU_XDWP2,0 AS PACU_XDWP3,0 AS PACU_XDWP4,'' AS PACU_XDWPMC,0 AS PACU_SSSW1,0 AS PACU_SSSW2,'' AS PACU_SSSWMC,'' AS PACU_SSSWJS,0 AS PACU_XueZiPin1,0 AS PACU_XueZiPin2,'' AS PACU_XueZiPinMC,
0 AS PACU_JMTL1,0 AS PACU_JMTL2,0 AS PACU_JMTL3,0 AS PACU_JMTL4,0 AS PACU_JMTL5,0 AS PACU_PCABeng1,0 AS PACU_PCABeng2,0 AS PACU_PCABengTJ1,0 AS PACU_PCABengTJ2,
0 AS PACU_SHLZ1,0 AS PACU_SHLZ2,0 AS PACU_SHLZ3,'' AS PACU_SHLZMC,0 AS PACU_PFQK1,0 AS PACU_PFQK2,0 AS PACU_PFQK3,'' AS PACU_PFQKMC,0 AS PACU_HZQX1,0 AS PACU_HZQX2,'' AS PACU_PACUYSQM,'' AS PACU_HSQM,
b.PATIENT_NAME,b.SEX,b.AGE,b.NURSE_CELL_NAME,b.DEPARTMENT_NAME,b.BED_NO,b.PATIENT_ID  
              from V_YDHL_PATIENT b  where b.PATIENT_ID  = '" + p1 + "' and b.VISIT_ID='" + p2 + "' ";

                //设置 ShowPrintDlg 属性，让点击工具栏中的打印按钮时不显示打印对话框
                axGRPrintViewer1.ShowPrintDlg = false;

                try
                {
                    if (File.Exists(System.Windows.Forms.Application.StartupPath + @"\GRFModel\Ydhl_GRF\手术患者交接单.grf"))
                    {
                        Report.LoadFromFile(System.Windows.Forms.Application.StartupPath + @"\GRFModel\Ydhl_GRF\手术患者交接单.grf");
                    }
                    else
                    {
                        Report.LoadFromFile(@"../../Ydhl_GRF/手术患者交接单.grf");
                    }
                }
                catch (Exception ex)
                {
                    XtraMessageBox.Show("加载临时医嘱表单失败，请检查文件Ydhl_GRF/手术患者交接单.grf是否存在");
                    WriteLog.WriteLogString(ex.Message + ".  加载临时医嘱表单失败，请检查文件Ydhl_GRF/Order-LZ.grf是否存在");
                }

                Report.DetailGrid.Recordset.QuerySQL = select;

                axGRPrintViewer1.Report = Report;
                axGRPrintViewer1.Start();
            }
            else if (ret.Code == 0)
            {
                MessageBox.Show(ret.M);
            }
        }
    }
}
